package bejar;

import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;

public class ReadSharp {
	
	private static class FrameShower implements Runnable {
     final Frame frame;
     public FrameShower(Frame frame) {
       this.frame = frame;
     }
     public void run() {
       frame.show();
     }
   }
	
   public static void main(String args[])
    throws IOException {
     if (args.length != 1) {
       System.err.println(
         "Please include image filename on command line");
       System.exit(-1);
     }
     // Read
     File file = new File(args[0]);
     BufferedImage input = ImageIO.read(file);
     // Convert
     Kernel sharpKernel =
             new Kernel(3, 3, new float[] {
        0.0f, -1.0f,  0.0f,
        -1.0f,  5.0f, -1.0f,
       0.0f, -1.0f,  0.0f
     });   
     ConvolveOp convolveOp = new ConvolveOp(sharpKernel, ConvolveOp.EDGE_NO_OP, null);
     
     int width = input.getWidth();
     int height = input.getHeight();
     
     BufferedImage output = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

      convolveOp.filter(input, output);
      
      
     // Make screen
     Icon icon = new ImageIcon(output);
     JLabel label = new JLabel(icon);
     JFrame frame = new JFrame("Sharp Image");
     frame.setDefaultCloseOperation(
       JFrame.EXIT_ON_CLOSE);
     frame.getContentPane().add(
       label, BorderLayout.CENTER);
     frame.pack();
     // Show
     Runnable runner = new FrameShower(frame);
     EventQueue.invokeLater(runner);
   }

}
